/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package control;

import handler.DatabaseConnection;
import java.io.FileNotFoundException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import mappers.CommodityMapper;
import model.Commodity;

/**
 *
 * @author Benjamin
 */
public class CommoditySystem {
    private static CommoditySystem instance;
    private ArrayList<Commodity> commodities;
    
    private CommoditySystem() throws SQLException, FileNotFoundException {
        commodities = CommodityMapper.getInstance().getTable();
        
        for (Commodity commodity : commodities) {
            System.out.println(commodity.getId());
        }
    }
    
    public ArrayList<Commodity> getCommodities() throws SQLException, FileNotFoundException{
        return commodities;
    }
    
    public void setCommodities(ArrayList<Commodity> commodities){
        this.commodities = commodities;
    }
    
    public static CommoditySystem getInstance() throws SQLException, FileNotFoundException {
        if(instance == null){
            instance = new CommoditySystem();
        }
        return instance;
    }
    
    public void connect() throws SQLException, FileNotFoundException{
        DatabaseConnection.getInstance().connect(); 
    }
    
    public Connection getConnection() throws SQLException, FileNotFoundException{
        return DatabaseConnection.getInstance().getConnection();        
    }
    
}
